package interfaze;

import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import logic.Utilities;

@SuppressWarnings("serial")
public class SpaceInvadersMainMenuPanel extends JPanel implements ActionListener, MouseListener {
	
	SuperArcade2in1 window;
	private JButton bNewGame = new JButton("New Game");
	private JButton bOptions = new JButton("Options");
	private JButton bHiScores = new JButton("High Scores");
	private JButton bQuit = new JButton("Back");
	private JLabel background = new JLabel();
	private Font font;
	
	public SpaceInvadersMainMenuPanel(SuperArcade2in1 window) {
		this.window = window;
		this.setLayout(null);
		
		font = new Font("Helvetica", Font.PLAIN, Math.round(12 * window.xScale));
		
		//Setting Background
		Image image = Utilities.loadImage("res/EarthDefenderTitle.png");
		if(window.xScale != 1 || window.yScale != 1) {
			image = Utilities.resizeImage(window.xScale, window.yScale, "res/EarthDefenderTitle.png");
		}
		background.setIcon(new ImageIcon(image));
		background.setBounds(0, 0, image.getWidth(null), image.getHeight(null));
		
		bNewGame.setFont(font);
		bNewGame.setBounds(Math.round(50 * window.xScale), Math.round(225 * window.yScale), 
				Math.round(117 * window.xScale), Math.round(29 * window.yScale));
		bHiScores.setFont(font);
		bHiScores.setBounds(Math.round(110 * window.xScale), Math.round(300 * window.yScale),
				Math.round(117 * window.xScale), Math.round(29 * window.yScale));
		bOptions.setFont(font);
		bOptions.setBounds(Math.round(170 * window.xScale), Math.round(375 * window.yScale),
				Math.round(117 * window.xScale), Math.round(29 * window.yScale));
		bQuit.setFont(font);
		bQuit.setBounds(Math.round(230 * window.xScale), Math.round(450 * window.yScale), 
				Math.round(117 * window.xScale), Math.round(29 * window.yScale));
		
		this.add(bNewGame);
		this.add(bOptions);
		this.add(bHiScores);
		this.add(bQuit);
		this.add(background);
		
		bNewGame.addActionListener(this);
		bNewGame.addMouseListener(this);
		bHiScores.addActionListener(this);
		bHiScores.addMouseListener(this);
		bOptions.addActionListener(this);
		bOptions.addMouseListener(this);
		bQuit.addActionListener(this);
		bQuit.addMouseListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource().equals(bNewGame)) {
			window.add(new SpaceInvadersGamingPanel(window));
			this.setVisible(false);
			window.remove(this);
		} else if(e.getSource().equals(bHiScores)) {
			window.add(new SpaceInvadersHiScorePanel(window));
			this.setVisible(false);
			window.remove(this);
		} else if(e.getSource().equals(bOptions)) {
			window.add(new SpaceInvadersOptionsPanel(window));
			this.setVisible(false);
			window.remove(this);
		} else if(e.getSource().equals(bQuit)) {
			window.add(new GameSelectorPanel(window));
			this.setVisible(false);
			window.remove(this);
		}
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		if(e.getSource().equals(bNewGame)) {
			logic.Utilities.buttonEffect(bNewGame, 5, window.xScale, window.yScale);
		} else if(e.getSource().equals(bHiScores)) {
			logic.Utilities.buttonEffect(bHiScores, 5, window.xScale, window.yScale);
		} else if(e.getSource().equals(bOptions)) {
			logic.Utilities.buttonEffect(bOptions, 5, window.xScale, window.yScale);
		} else if(e.getSource().equals(bQuit)) {
			logic.Utilities.buttonEffect(bQuit, 5, window.xScale, window.yScale);
		}
	}

	@Override
	public void mouseExited(MouseEvent e) {
		if(e.getSource().equals(bNewGame)) {
			logic.Utilities.buttonEffect(bNewGame, -5, window.xScale, window.yScale);
		} else if(e.getSource().equals(bHiScores)) {
			logic.Utilities.buttonEffect(bHiScores, -5, window.xScale, window.yScale);
		} else if(e.getSource().equals(bOptions)) {
			logic.Utilities.buttonEffect(bOptions, -5, window.xScale, window.yScale);
		} else if(e.getSource().equals(bQuit)) {
			logic.Utilities.buttonEffect(bQuit, -5, window.xScale, window.yScale);
		}
	}

	@Override
	public void mousePressed(MouseEvent e) {
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		
	}
}
